----------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata5-1empcen.log
  log type:  text
 opened on:  21 Jul 2016, 11:56:08

. 
. use "..\..\data\empcensus\source\CIC_ADJ-02-03.dta", clear

. tostring cic02 cic03, gen(cs02 cs03)
cs02 generated as str4
cs03 generated as str4

. gen cs02_3d=substr(cs02,1,3)

. gen cs03_3d=substr(cs03,1,3)

. sort cs02

. duplicates tag cs02, gen(check)

Duplicates in terms of cs02

. order check cs02 cs03

. 
. * Fix one-to-many matches
. sort cs02 cs03_3d

. by cs02: gen first=cs03_3d if _n==1
(57 missing values generated)

. by cs02: replace first=first[1] if first==""
(57 real changes made)

. by cs02: gen last=cs03_3d if _n==_N
(57 missing values generated)

. by cs02: replace last=last[_N] if last==""
(57 real changes made)

. replace check=0 if check~=0 & first==last
(63 real changes made)

. preserve

. 
. import excel using "..\..\data\empcensus\source\industrycodecheck.xlsx", clear f
> irstrow allstring

. tempfile manu

. save `manu'
file C:\Users\NATE~1.BAU\AppData\Local\Temp\ST_01000002.tmp saved

. 
. restore

. merge 1:1 cs02 cs03 cs02_3d cs03_3d using `manu', nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                           554
        from master                       554  
        from using                          0  

    matched                                39  
    -----------------------------------------

. drop if drop=="1"
(22 observations deleted)

. 
. duplicates drop cs02 cs03_3d, force

Duplicates in terms of cs02 cs03_3d

(35 observations deleted)

. 
. keep cs02 cs03 cic03 cic02

. save "..\..\data\empcensus\generated\cic_correspondence.dta", replace
file ..\..\data\empcensus\generated\cic_correspondence.dta saved

. 
. log close
      name:  <unnamed>
       log:  C:\research\china\decentralization\restat_data\tabdata\dofiles\tab_da
> ta\tabdata5-1empcen.log
  log type:  text
 closed on:  21 Jul 2016, 11:56:08
----------------------------------------------------------------------------------
